package com.wthink.hzgj.util.adapter

import androidx.databinding.ViewDataBinding
import com.wthink.hzgj.util.LifecycleViewOwner

abstract class LifecycleBaseAdapter<T : LifecycleBaseViewHolder> : BaseAdapter<T>() {

    override fun onViewAttachedToWindow(holder: T) {
        super.onViewAttachedToWindow(holder)
        holder.onAppear()
    }

    override fun onViewDetachedFromWindow(holder: T) {
        super.onViewDetachedFromWindow(holder)
        holder.onDisappear()
    }

}


open class LifecycleBaseViewHolder(dataBinding: ViewDataBinding, variableId: Int?=null) :
    BaseViewHolder(dataBinding, variableId) {
    val lifecycleViewOwner = LifecycleViewOwner()

    init {
        dataBinding.lifecycleOwner = lifecycleViewOwner
    }

    fun onAppear() {
        lifecycleViewOwner.onAppear()
    }

    fun onDisappear() {
        lifecycleViewOwner.onDisappear()
    }
}
